<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	
	public $base_uri = array();
			
	function __construct(){
			parent::__construct();
			$main =   & get_config();
			$this->base_uri['base_url'] = $main['base_url'];
			
			$idd = $this->session->userdata('iduser');
			
			
			if(isset($idd) and $this->input->get('iduser') != "0"){
				//$this->session->set_userdata('session_id', $this->input->get('iduser'));
				$this->session->set_userdata('id_user', $this->input->get('iduser'));
			};
			
						
	
	}
	
	public function index()
	{
		//var_dump($this->session->all_userdata());
		//echo 'id^'.$this->input->get('iduser');

		if($this->input->get('iduser') !== '0'){
				
				if($this->input->get('mon')){
					$mon = $this->input->get('mon');
				}else{
				    $mon = 0;
				}
				
				$this->load->model('Userviewmodel');
						
				$data = array();
				$data['data'] = $this->Userviewmodel->get($this->session->userdata('id_user'), $mon); 
				$data['mon'] = $this->Userviewmodel->getdates($this->session->userdata('id_user'));
				//var_dump($data['data']);
						
				$data['base_url'] = $this->base_uri['base_url'];
				$data['id_user'] = $this->session->userdata('id_user');

				
				
				$this->load->view('header_view');
				if($this->session->userdata('id_user') == 42) $this->load->view('main_view', $this->base_uri);
				$this->load->view('user_view', $data);
		}else{
				$this->session->unset_userdata('id_user');
				$this->load->view('header_view');
				echo "Необходима регистрация";
		}
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
